package com.snakegame.ui;

import com.snakegame.core.GameManager;
import com.snakegame.config.GameState;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
 * 开始菜单面板，游戏启动后显示的第一个界面
 */
public class StartMenuPanel extends JPanel {
    private GameManager gameManager;
    private GameFrame gameFrame;
    
    public StartMenuPanel(GameManager gameManager, GameFrame gameFrame) {
        this.gameManager = gameManager;
        this.gameFrame = gameFrame;
        
        setLayout(new GridBagLayout());
        GridBagConstraints gbc = new GridBagConstraints();
        gbc.gridx = 0;
        gbc.insets = new Insets(10, 0, 10, 0);
        gbc.fill = GridBagConstraints.HORIZONTAL;
        gbc.anchor = GridBagConstraints.CENTER;
        gbc.ipadx = 100;
        gbc.ipady = 10;
        
        // 游戏标题
        JLabel titleLabel = new JLabel("贪吃蛇游戏");
        titleLabel.setFont(new Font("宋体", Font.BOLD, 36));
        gbc.gridy = 0;
        gbc.weighty = 0.5;
        add(titleLabel, gbc);
        
        // 开始游戏按钮
        JButton startButton = new JButton("开始游戏");
        startButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                gameManager.startGame();
                gameFrame.showPanel("GAME");
            }
        });
        gbc.gridy = 1;
        gbc.weighty = 0;
        add(startButton, gbc);
        
        // 选择地图按钮
        JButton mapButton = new JButton("选择地图");
        mapButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                gameManager.setGameState(GameState.MAP_SELECTION);
                gameFrame.showPanel("MAP_SELECTION");
            }
        });
        gbc.gridy = 2;
        add(mapButton, gbc);
        
        // 选择模式按钮
        JButton modeButton = new JButton("选择模式");
        modeButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                gameManager.setGameState(GameState.MODE_SELECTION);
                gameFrame.showPanel("MODE_SELECTION");
            }
        });
        gbc.gridy = 3;
        add(modeButton, gbc);
        
        // 选择难度按钮
        JButton difficultyButton = new JButton("选择难度");
        difficultyButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                gameManager.setGameState(GameState.DIFFICULTY_SELECTION);
                gameFrame.showPanel("DIFFICULTY_SELECTION");
            }
        });
        gbc.gridy = 4;
        add(difficultyButton, gbc);
        
        // 退出按钮
        JButton exitButton = new JButton("退出游戏");
        exitButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                System.exit(0);
            }
        });
        gbc.gridy = 5;
        gbc.weighty = 0.5;
        add(exitButton, gbc);
        
        setBackground(Color.BLACK);
    }
}    